<?php
class RoleUserAction extends LoginAction
{
    public function index()
    {
        $this->display();
    }

    /**
     * 用户基本信息查看
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function user()
    {
        $RoleUserModel = D('RoleUser');
        $user = $this->getUserInfo();
        //执行修改
        if (isPost()) {
            $roles = getPost('roles');
            $RoleUserModel->setUserRloe($user['id'], $roles);
            $this->successMessage('角色调整完成！');
        }
        //获取用户角色信息
        $userRoles = $RoleUserModel->getUserRloe($user['id']);
        //获取用户不存在的角色信息
        $otherRoles = $RoleUserModel->getUserOtherRloe($user['id']);
        $this->assign('userRoles', $userRoles);
        $this->assign('otherRoles', $otherRoles);
        $this->assign('user', $user);
        $this->display();
    }

    /**
     * 用户信息获取
     * @return Array 用户信息
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getUserInfo()
    {
        $uid = intval(getGet('uid'));
        if (!$uid) {
            $this->error('提供用户信息不正确!');
        }
        else if ($uid == 1) {
            $this->error('你没有权利修改!');
        }
        $UsersModel = M('Users');
        $user = $UsersModel->find($uid);
        if ($user) {
            return $user;
        } else {
            $this->error('用户权限用户数据获取失败！');
        }
    }
}

?>